import request from '@/utils/request'
import { encryptedData } from '@/utils/encrypt'
import { loginRSA, tokenName } from '@/config'

export async function login(data) {
  if (loginRSA) {
    data = await encryptedData(data)
  }
  return request({
    url: '/manager/login',
    method: 'post',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
    },
    data,
  })
}

export function getUserInfo(accessToken) {
  return {
    code: 200,
    msg: 'success',
    data: {
      permissions: ['admin'],
      username: 'admin',
      avatar: 'https://i.gtimg.cn/club/item/face/img/2/15922_100.gif',
    },
  }
  // return request({
  //   url: '/userInfo',
  //   method: 'post',
  //   data: {
  //     [tokenName]: accessToken,
  //   },
  // })
}

export function logout() {
  return request({
    url: '/manager/logout',
    method: 'post',
  })
}

export function register() {
  return request({
    url: '/register',
    method: 'post',
  })
}
